//
//  NSString+WebErrorCode.m
//  ZhiNengKong_APILib
//
//  Created by 宣佚 on 15/5/26.
//  Copyright (c) 2015年 Andon Health Co,.Ltd. All rights reserved.
//

#import "NSString+WebErrorCode.h"

@implementation NSString (WebErrorCode)

/**
 *  生成错误码信息（根据协议错误码定义）
 *
 *  @return 错误信息字典集
 */
-(NSDictionary *)createBaseWebErrorCodeAndMessage
{
    NSMutableDictionary *errorCodeAndMessage = [[NSMutableDictionary alloc] initWithCapacity:10];
    
    //请根据API错误码及对应错误码解释进行添加
    /*
     *这部分为示例
    [errorCodeAndMessage setObject:@"成功" forKey:k1_1000];
    [errorCodeAndMessage setObject:@"请求缺少必须参数" forKey:k2_2001];
    [errorCodeAndMessage setObject:@"服务器内部错误" forKey:k3_5000];
    */
    [errorCodeAndMessage setObject:@"成功" forKey:k1_1000];
    
    [errorCodeAndMessage setObject:@"请求缺少必须参数" forKey:k2_2001];
    [errorCodeAndMessage setObject:@"SC或SV未授权" forKey:k2_2002];
    [errorCodeAndMessage setObject:@"手机号被占用" forKey:k2_2003];
    [errorCodeAndMessage setObject:@"错误的手机号格式" forKey:k2_2004];
    [errorCodeAndMessage setObject:@"发送短信失败" forKey:k2_2005];
    [errorCodeAndMessage setObject:@"错误的手机注册验证码" forKey:k2_2006];
    [errorCodeAndMessage setObject:@"注册失败" forKey:k2_2020];
    [errorCodeAndMessage setObject:@"服务器内部错误" forKey:k3_5000];
    NSDictionary *returnDic = [[NSDictionary alloc] initWithDictionary:errorCodeAndMessage];
    return returnDic;
}

/*!
 *  通过服务器传过来的ResulteMessage返回错误信息
 *
 *  @return 错误信息
 */
-(NSString *)ErrorCode
{
    NSDictionary *dic = [[NSDictionary alloc] init];
    dic = [self createBaseWebErrorCodeAndMessage];
    
    NSString *errorStr = @"";
    errorStr = dic[self];
    
    return errorStr;
}

@end
